package org.stragma.apply.util

import org.kiama.rewriting._
import org.kiama.rewriting.Rewriter.{id,fail,rulefs,Strategy,Term}

import org.stragma.apply.signatures.Apply._
import org.stragma.apply.util.LogicalOperators._

/*
 * This object consists of some of the math function used in Apply
 */
object String {
	/*
	 * Return the minimum of two strings
	 */
	def minstring(arg0 : Int,arg1 : Int) : Int = {
		val i = arg0.arg0.toInt
		val j = arg1.arg0.toInt
		if (i < j)
			Int(i.toString)
		else
			Int(j.toString)
	}
	
	/*
	 * Return the maximum of two strings
	 */
	def maxstring(arg0 : Int,arg1 : Int) : Int = {
		val i = arg0.arg0.toInt
		val j = arg1.arg0.toInt
		if (i < j)
			Int(j.toString)
		else
			Int(i.toString)
	}
	
	/*
	 * Returns the current term else a fail on comparing two strings
	 */
	def string_gt(arg0: String, arg1: String) : Strategy = {
		if (arg0 > arg1)
			id
		else
			fail
	}
}